var mysql = require('mysql');
var connection = mysql.createConnection({
    host : 'localhost',
    port:'3306',
    user : 'root',
    password : '123456',
    database : 'test'
});
//有参数的方法
exports.query=function(sql,json,callback){
    connection.connect();
    connection.query(sql,json, function (error, results, fields) {
        if (error) throw error;
        console.log(sql);
        console.log('The results is: ', results[0]);
        console.log('The fields is: ', fields);
        callback(results);
    });

    connection.end();
}

//无参数的查询
exports.find=function(sql,json,callback){
    connection.connect();
    connection.query(sql,json, function (error, results, fields) {
        if (error) throw error;
        console.log(sql);
        console.log('The results is: ', results[0]);
        console.log('The fields is: ', fields);
        callback(results);
    });

    connection.end();
}

